﻿using System;
using System.Collections;
using System.Web;
using THANHTUNGO.PORTAL.Components.Configuration.Items;
using THANHTUNGO.PORTAL.Components.UI;

namespace THANHTUNGO.PORTAL.Modules.MODULE.Controls
{
    public partial class CustomSetting : AddEditItemControl
    {
        private Module GetModule()
        {
            // Obtain Portal for this tab
            Components.Configuration.Items.Portal portal = (Components.Configuration.Items.Portal)HttpContext.Current.Items["Portal"];

            // Obtain selected module data
            foreach (Module _module in portal.ActiveTab.Modules)
            {
                if (_module.ID == this.ModuleID)
                    return _module;
            }
            return null;
        }

        protected override void OnInit(EventArgs e)
        {
            ButtonUpdate = this.btnApply;
            ButtonCancel = this.btnCancel;

            base.OnInit(e);
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            object value = this.GetModule();
            if (value != null)
            {
                SettingTable1.DataSource = new SortedList(this.Settings);
                SettingTable1.DataBind();
            }
        }

        protected override void OnUpdate(EventArgs e)
        {
            base.OnUpdate(e);
            object value = this.GetModule();
            if (value != null)
            {
                SettingTable1.UpdateControls(this.ModuleID);

            }
            // Redirect back to the portal home page
            ReturnToReferrerPage();
        }
    }
}